import miao.demo.dao.AccountDao;
import miao.demo.domain.Account;
import org.apache.ibatis.io.Resources;
import org.apache.ibatis.session.SqlSession;
import org.apache.ibatis.session.SqlSessionFactory;
import org.apache.ibatis.session.SqlSessionFactoryBuilder;

import java.io.IOException;
import java.io.InputStream;

public class App {
    public static void main(String[] args) throws Exception {
        //1. 加载MyBatis的核心配置文件，创建SqlSessionFactory对象
        String resource = "mybatis_config.xml"; //配置文件路径 以resources为起点
        InputStream inputStream = Resources.getResourceAsStream(resource);
        SqlSessionFactory sqlSessionFactory = new SqlSessionFactoryBuilder().build(inputStream);

        //2. 获取SqlSession对象，用于执行SQL语句
        SqlSession sqlSession = sqlSessionFactory.openSession();

        //3.获取mapper
        AccountDao accountDao = sqlSession.getMapper(AccountDao.class);

        //4.执行sql
        Account user = accountDao.findById(1);

        System.out.println(user);



    }
}
